<?php
class PersistanceArticle extends Article {
	
	
	public function __construct($serie){
		parent::__construct($serie); //Appel du constructeur parent
	}
	
	public function addDB($date, $fournisseur){
		$sql = "LOCK TABLES Article WRITE, EntreeStock WRITE;";
		$result = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
		$sql = "INSERT INTO Article VALUES ('".$this->getNumSerie()."', '".$this->getCodeBarre()."', '".$this->getTypeArticle()."', '".$this->getEntrepot()."');";
		$result = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
		$sql="INSERT INTO EntreeStock(dateEntree,	articleNS, entrepotIS, societeId) VALUES ('$date', '".$this->getNumSerie()."', '".$this->getEntrepot()."', '$fournisseur');";
		$result = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
		$sql="UNLOCK TABLES;";
		
		$result = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
		
		// Liberation des resultats
		mysql_free_result($result);

		
	}
	
	public function sortirDB($date, $client, $entrepot){
		$sql = "LOCK TABLES Article WRITE, SortieStock WRITE;";
		$result = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
		
		$sql = "UPDATE Article SET entrepot = '$entrepot' WHERE numSerie = '".$this->getNumSerie()."';";
		$result = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
		
		$sql = "INSERT INTO SortieStock(dateSortie,	articleNS, entrepotIS, societeId) VALUES ('$date', '".$this->getNumSerie()."', '".$entrepot."', '$client');";
		$result = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
		
		$sql = "UNLOCK TABLES;";
		$result = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
		
		// Liberation des resultats
		mysql_free_result($result);
	}
	
	public function modifierEntrepotDB($date, $entrepot){
		$sql = "LOCK TABLES Article WRITE, SortieStock WRITE;";
		$result = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
		
		$sql = "UPDATE Article SET entrepot = '$entrepot' WHERE numSerie = '".$this->getNumSerie()."';";
		$result = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
		
		$sql = "INSERT INTO SortieStock(dateSortie,	articleNS, entrepotIS, societeId) VALUES ('$date', '".$this->getNumSerie()."', '".$entrepot."', '1');";
		$result = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
		
		$sql = "INSERT INTO EntreeStock(dateEntree,	articleNS, entrepotIS, societeId) VALUES ('$date', '".$this->getNumSerie()."', '".$entrepot."', '1');";
		$result = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
		
		$sql = "UNLOCK TABLES;";
		$result = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());

		
		// Liberation des resultats
		mysql_free_result($result);
	}
	

}

?>
